package com.servlet.model.base;

import java.io.Serializable;
import java.sql.Date;

/**
 * News dans la base de donnée
 * @author Jing Jing
 */
public class News implements Comparable<News> , Serializable
{

	private String email_user1;
	private String email_user2;
	private Date date_publish;
	private String info_sup;
	/**
	 * Le type de la news
	 * 0 : pour modif profil
	 * 1 : invitation
	 * 2 : nouveau contact pour toi
	 * 3 : nouveau contact pour quelqu'un
	 * 4 : suppresion de contact
	 */
	private int genre;
	private Profile profile3;
	private Profile profile2;
	private Profile profile1;
	
	private int id;
	

	public News()
	{
		this.email_user1 = null;
		this.email_user2 = null;
		this.date_publish = null;
		genre = 0;
		this.info_sup = null;
	}
	
	public News(String email_user1, String email_user2, Date date_publish, int genre) {
		this.email_user1 = email_user1;
		this.email_user2 = email_user2;
		this.date_publish = date_publish;
		this.genre = genre;
		this.info_sup = null;
	}
	
	public News(String email_user1, String email_user2, Date date_publish, int genre, String info_sup) {
		this.email_user1 = email_user1;
		this.email_user2 = email_user2;
		this.date_publish = date_publish;
		this.genre = genre;
		this.info_sup = info_sup;
	}

	public String getInfo_sup()
	{
		return this.info_sup;
	}
	
	public int getGenre()
	{
		return this.genre;
	}
	
	public String getEmail_user1() {
		return email_user1;
	}

	public String getEmail_user2() {
		return email_user2;
	}

	public Profile getProfile2() {
		return profile2;
	}

	public Profile getProfile1() {
		return profile1;
	}
	
	public Profile getProfile3() {
		return profile3;
	}

	public void setId(int id) {
		this.id = id;
	}

	public void setInfo_sup(String info_sup)
	{
		this.info_sup = info_sup;
	}
	
	public void setGenre(int genre)
	{
		this.genre = genre;
	}
	
	public Date setDate_publish() {
		return date_publish;
	}
	
	public void setEmail_user1(String email_user1) {
		this.email_user1 = email_user1;
	}

	public void setEmail_user2(String email_user2) {
		this.email_user2 =  email_user2;
	}

	public void setDate_publish(Date date_publish) {
		this.date_publish = date_publish;
	}

	public String generateInsertSQL()
	{
		String insertSQL = "INSERT INTO news VALUES ('" + email_user1 + "' ,'"
				+ email_user2 + "'";
		if(date_publish != null)
			insertSQL += " ,'"+date_publish+"'";
		else
			insertSQL += " , null";
		
		insertSQL += ", "+genre;
		
		if(info_sup != null)
			insertSQL += " ,'"+info_sup+"'";
		else
			insertSQL += " , null";
		
		insertSQL += ")";
		
		System.out.println(insertSQL);
		
		return insertSQL;
	}

	public String generateDeleteSQL() {
		String deleteSQL = "DELETE FROM news WHERE id='" + id + "'";
		
		return deleteSQL;
	}

	public void setProfile1(Profile p)
	{
		this.profile1 = p;
	}


	public void setProfile2(Profile p)
	{
		this.profile2 = p;
	}

	public int compareTo(News arg0)
	{
		if( date_publish.after( arg0.date_publish) )
			return 1;
		return -1;
	}

	public void setProfile3(Profile p)
	{
		this.profile3 = p;
	}
}
